/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.media.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.media.entity.HkMediaCategoryCarousel;
import com.thinkgem.jeesite.modules.hk.media.service.HkMediaCategoryCarouselService;

/**
 * 自媒体分类轮播图Controller
 * @author 自媒体分类轮播图
 * @version 2018-04-13
 */
@Controller
@RequestMapping(value = "${adminPath}/media/hkMediaCategoryCarousel")
public class HkMediaCategoryCarouselController extends BaseController {

	@Autowired
	private HkMediaCategoryCarouselService hkMediaCategoryCarouselService;
	
	@ModelAttribute
	public HkMediaCategoryCarousel get(@RequestParam(required=false) String id) {
		HkMediaCategoryCarousel entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkMediaCategoryCarouselService.get(id);
		}
		if (entity == null){
			entity = new HkMediaCategoryCarousel();
		}
		return entity;
	}
	
	@RequiresPermissions("media:hkMediaCategoryCarousel:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkMediaCategoryCarousel hkMediaCategoryCarousel, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkMediaCategoryCarousel> page = hkMediaCategoryCarouselService.findPage(new Page<HkMediaCategoryCarousel>(request, response), hkMediaCategoryCarousel); 
		model.addAttribute("page", page);
		return "hk/media/hkMediaCategoryCarouselList";
	}

	@RequiresPermissions("media:hkMediaCategoryCarousel:view")
	@RequestMapping(value = "form")
	public String form(HkMediaCategoryCarousel hkMediaCategoryCarousel, Model model) {
		model.addAttribute("hkMediaCategoryCarousel", hkMediaCategoryCarousel);
		return "hk/media/hkMediaCategoryCarouselForm";
	}

	@RequiresPermissions("media:hkMediaCategoryCarousel:edit")
	@RequestMapping(value = "save")
	public String save(HkMediaCategoryCarousel hkMediaCategoryCarousel, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkMediaCategoryCarousel)){
			return form(hkMediaCategoryCarousel, model);
		}
		hkMediaCategoryCarouselService.save(hkMediaCategoryCarousel);
		addMessage(redirectAttributes, "保存自媒体分类轮播图成功");
		return "redirect:"+Global.getAdminPath()+"/media/hkMediaCategoryCarousel/?repage";
	}
	
	@RequiresPermissions("media:hkMediaCategoryCarousel:edit")
	@RequestMapping(value = "delete")
	public String delete(HkMediaCategoryCarousel hkMediaCategoryCarousel, RedirectAttributes redirectAttributes) {
		hkMediaCategoryCarouselService.delete(hkMediaCategoryCarousel);
		addMessage(redirectAttributes, "删除自媒体分类轮播图成功");
		return "redirect:"+Global.getAdminPath()+"/media/hkMediaCategoryCarousel/?repage";
	}

}